from django.db import models

# Create your models here.

# 功能分析
# 【一】检查用户是否存在
# 【二】注册用户
# 【三】修改用户
# 【四】根据用户名查询用户
# 【五】用户登录
# 【六】校验用户是否登录
# 【七】用户退出登陆
# 【八】注销用户

from django.contrib.auth.models import AbstractUser


# 创建用户表
class User(models.Model):
    del_tag_choices = ( 
        (0, "正常"),
        (1, "删除")
    )
    username = models.CharField(max_length=255, verbose_name="用户名", help_text="用户名", unique=True)
    password = models.CharField(max_length=512, verbose_name="密码", help_text="密码")
    real_name = models.CharField(max_length=255, verbose_name="真实姓名", help_text="真实姓名")
    phone = models.CharField(max_length=128, verbose_name="手机号码", help_text="手机号码")
    mail = models.CharField(max_length=512, verbose_name="邮箱", help_text="邮箱")
    deletion_time = models.DateTimeField(verbose_name="注销时间", help_text="注销时间", null=True, blank=True)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间", help_text="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间", help_text="更新时间")
    del_tag = models.IntegerField(choices=del_tag_choices, default=0, verbose_name="删除标志", help_text="删除标志")

    class Meta:
        db_table = "user"
        verbose_name = "用户表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username

    def get_del_tag_display(self):
        return self.del_tag_choices[self.del_tag][1]
